package com.studyyoun.android.nonghe.home.http;

import com.studyyoun.android.androidcommonbaselibrary.okhttp.callback.OkhttpCommonCallBack;
import com.studyyoun.android.androidcommonbaselibrary.okhttp.client.OkhttpCommonClient;
import com.studyyoun.android.nonghe.home.model.ArtModel;
import com.studyyoun.android.nonghe.home.model.CommonSearcherModel;
import com.studyyoun.android.nonghe.home.model.VideoModel;
import com.studyyoun.android.nonghe.http.HttpCallBackHelper;
import com.studyyoun.android.nonghe.http.HttpUrlHelper;

import java.util.List;
import java.util.concurrent.ConcurrentHashMap;

/**
 * Created by androidlongs on 2017/9/25.
 */

public class HomeHttpManager {
    private HomeHttpManager(){

    }

    private static class  SingleHomeHttpManager{
        private static HomeHttpManager sHomeManager= new HomeHttpManager();
    }

    public static HomeHttpManager getInstance(){
        return SingleHomeHttpManager.sHomeManager;
    }


    /**
     * 获取文章列表
     */
    public void getArtListFunction(int type, int currentIndex, int pageSize, final HttpCallBackHelper<List<ArtModel>> callBackHelper){


        String url = HttpUrlHelper.getArtListIndexUrl;
        ConcurrentHashMap<String,String> key = new ConcurrentHashMap<>();
        key.put("pageIndex",""+currentIndex);
        key.put("pageSize",""+pageSize);
        key.put("pageType",""+type);

        OkhttpCommonClient.sentPostRequest(url, key, new OkhttpCommonCallBack(ArtModel.class) {
            @Override
            public void onSuccess(Object obj) {
                if (callBackHelper != null) {
                    callBackHelper.onSuccess((List<ArtModel>) obj);
                }
            }

            @Override
            public void onFaile(Object obj) {
                if (callBackHelper != null) {
                    callBackHelper.onFaile("faile");
                }
            }
        });

    }

    /**
     * 获取视频列表
     */
    public void getVideoListFunction(int type, int currentIndex, int pageSize, final HttpCallBackHelper<List<VideoModel>> callBackHelper){


        String url = HttpUrlHelper.sGetVideoListFromIndexUrl;
        ConcurrentHashMap<String,String> key = new ConcurrentHashMap<>();
        key.put("pageIndex",""+currentIndex);
        key.put("pageSize",""+pageSize);
        key.put("pageType",""+type);

        OkhttpCommonClient.sentPostRequest(url, key, new OkhttpCommonCallBack(VideoModel.class) {
            @Override
            public void onSuccess(Object obj) {
                if (callBackHelper != null) {
                    callBackHelper.onSuccess((List<VideoModel>) obj);
                }
            }

            @Override
            public void onFaile(Object obj) {
                if (callBackHelper != null) {
                    callBackHelper.onFaile("faile");
                }
            }
        });

    }

    /**
     * 搜索列表
     */
    public void getArtAndVideoListFromNameFunction(String type, int currentIndex, int pageSize, final HttpCallBackHelper<CommonSearcherModel> callBackHelper){


        String url = HttpUrlHelper.sSearchListUrl;
        ConcurrentHashMap<String,String> key = new ConcurrentHashMap<>();
        key.put("pageIndex",""+currentIndex);
        key.put("pageSize",""+pageSize);
        key.put("pageType",""+type);

        OkhttpCommonClient.sentPostRequest(url, key, new OkhttpCommonCallBack(CommonSearcherModel.class) {
            @Override
            public void onSuccess(Object obj) {
                if (callBackHelper != null) {
                    callBackHelper.onSuccess((CommonSearcherModel) obj);
                }
            }

            @Override
            public void onFaile(Object obj) {
                if (callBackHelper != null) {
                    callBackHelper.onFaile("faile");
                }
            }
        });

    }

    /**
     * 搜索全部列表
     */
    public void getAllArtAndVideoListFromNameFunction(String type, int currentIndex, int pageSize, final HttpCallBackHelper<CommonSearcherModel> callBackHelper){


        String url = HttpUrlHelper.sSearchAllListUrl;
        ConcurrentHashMap<String,String> key = new ConcurrentHashMap<>();
        key.put("pageIndex",""+currentIndex);
        key.put("pageSize",""+pageSize);
        key.put("pageType",""+type);

        OkhttpCommonClient.sentPostRequest(url, key, new OkhttpCommonCallBack(CommonSearcherModel.class) {
            @Override
            public void onSuccess(Object obj) {
                if (callBackHelper != null) {
                    callBackHelper.onSuccess((CommonSearcherModel) obj);
                }
            }

            @Override
            public void onFaile(Object obj) {
                if (callBackHelper != null) {
                    callBackHelper.onFaile("faile");
                }
            }
        });

    }

}
